package com.cms.service.impl;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cms.service.DataRowService;
import com.cms.service.SubjectDataService;
import com.cms.service.TemplateService;
import com.core.page.Pagination;

@Service
public class SubjectDataServiceImpl implements SubjectDataService {
	
	@Autowired
	private TemplateService templateService;
	
	@Autowired
	private DataRowService dataRowService;
	
	public List getSubjects(String idSubject) {
		// TODO 自动生成的方法存根
		return dataRowService.getValuesList(Long.valueOf(idSubject));
	}

	public Pagination<Map> getSubjects(String idSubject, Pagination<Map> pagination) {
		List list = dataRowService.getValuesList(Long.valueOf(idSubject), pagination.getPageNum(), pagination.getPageSize());
		if(list!=null){
			pagination.setTotalItemsCount(list.size());
			pagination.setItems(list);
		}
		return pagination;
	}

	public Map getSubject(String idSubject, String itemId) {
		return dataRowService.getValuesByRowNum(Long.valueOf(idSubject), Long.valueOf(itemId));
	}

	public Object getSubjectItemValue(String idSubject, String itemId,
			String itemName) {
		return dataRowService.getValueByRowNum(Long.valueOf(idSubject), Long.valueOf(itemId), itemName);
	}

	public int getSubjectSize(String idSubject) {
		// TODO 自动生成的方法存根
		return dataRowService.getRowCount(Long.valueOf(idSubject));
	}

	public List getSubjects(String idSubject, Map params) {
		return dataRowService.getValuesList(Long.valueOf(idSubject), params);
	}

	public Pagination<Map> getSubjects(String idSubject, Map params, Pagination<Map> pagination) {
		List list = dataRowService.getValuesList(Long.valueOf(idSubject), pagination.getPageNum(), pagination.getPageSize(), params);
		if(list!=null){
			pagination.setTotalItemsCount(dataRowService.getRowCount(Long.valueOf(idSubject), params));
			pagination.setItems(list);
		}
		return pagination;
	}
	
	public String getRelativePathByKey(String key) {
		return templateService.getRelativePathByKey(key);
	}
	
	
	/**
	 * 生成测试用的一条数据
	 * @return
	 */
	private Map genTestData(){
		Map map = new LinkedHashMap();
		map.put("field1", "fields1value");
		map.put("field2", "fields2value");
		map.put("field3", "fields3value");
		return map;
	}
	
	/**
	 * 生成测试用的集合数据
	 * @return
	 */
	private List genTestList(){
		List list = new ArrayList();
		list.add(genTestData());
		return list;
	}

}
